import { translateByCode } from '@/lib/getTransData.js';
import validator from '../index.js';

export class GameLayoutEditCode_Rules { // 修改场次编码
  constructor() {
    this.code = [
      validator.required(translateByCode('请填写场次编码'), 'blur')
    ];
  }
}

export class GameLayoutSetCode_Rules { // 编码设置
  constructor() {
    this.prefix = [
      validator.required('请填写编码前缀', 'blur')
    ];
    this.start = [
      validator.required('请填写编码起始数', 'blur'),
      {
        validator (rule, value, callback) {
          const _regExp = /^[0-9]{0,}$/g;
          if (!_regExp.test(value)) {
            callback(new Error('格式不正确，编码起始数仅支持数字'));
          } else {
            callback();
          }
        },
        trigger: 'blur'
      }
    ];
    this.step = [
      validator.required('请填步长', 'blur'),
      {
        validator (rule, value, callback) {
          const _regExp = /^[1-9][0-9]{0,}$/g;
          if (!_regExp.test(value)) {
            callback(new Error('格式不正确，步长仅支持整数数字，且不能为0'));
          } else {
            callback();
          }
        },
        trigger: 'blur'
      }
    ];
    this.length = [
      validator.required('请填编码长度', 'blur'),
      {
        validator (rule, value, callback) {
          const _regExp = /^[1-9][0-9]{0,}$/g;
          if (!_regExp.test(value)) {
            callback(new Error('格式不正确，编码长度仅支持数字，且不能为0'));
          } else {
            callback();
          }
        },
        trigger: 'blur'
      }
    ];
  }
}

export class GameLayoutSelectTable_Rules { // 场次选择
  constructor() {
    // 单元选择：必选
    this.value = [
      validator.required(translateByCode('rules.requiredUserName'), 'change')
    ];
    // 起始场次序号：必填且仅为正整数或0
    this.startNum = [
      validator.required(translateByCode('rules.execte.gameLayout.startNumNull')),
      {
        validator (rule, value, callback) {
          const _regExp = /^[1-9][0-9]{0,}$/g;
          if (!_regExp.test(value)) {
            callback(translateByCode('rules.execte.gameLayout.startNum'));
          } else {
            callback();
          }
        },
        trigger: 'blur'
      }
    ];
    // 截止场次序号：必填且仅为正整数或0
    this.endNum = [
      validator.required(translateByCode('rules.execte.gameLayout.endNumNull')),
      {
        validator (rule, value, callback) {
          const _regExp = /^[1-9][0-9]{0,}$/g;
          if (!_regExp.test(value)) {
            callback(translateByCode('rules.execte.gameLayout.endNum'));
          } else {
            callback();
          }
        },
        trigger: 'blur'
      }
    ];
  }
}

export class GameLayoutClearArrange_Rules { // 清除场次
  constructor() {
    // 单元选择：必选
    this.value = [
      validator.required(translateByCode('rules.requiredUserName'), 'change')
    ];
  }
}

export class GameLayoutMigrateUnit_Rules { // 清除场次
  constructor() {
    // 单元选择：必选
    this.date = [
      validator.required(translateByCode('请选择编排日期'), 'change')
    ];
    this.location = [
      validator.required(translateByCode('请选择场地'), 'change')
    ];
    this.destinationSessionId = [
      validator.required(translateByCode('请选择时间单元'), 'change')
    ];
    this.positionType = [
      validator.required(translateByCode('请选择插入位置'), 'change')
    ];
    this.positionNum = [
      validator.required(translateByCode('请输入位置序号'), 'bulr'),
      {
        validator (rule, value, callback) {
          const _regExp = /^[0-9]{0,}$/g;
          if (!_regExp.test(value)) {
            callback(new Error('格式错误，仅支持数字'));
          } else {
            callback();
          }
        },
        trigger: 'blur'
      },
      {
        validator (rule, value, callback) {
          const _num = Number(value);
          if (_num <= 0) {
            callback(new Error('位置序号不能小于0'));
          } else {
            callback();
          }
        },
        trigger: 'blur'
      }
    ];
  }
}

export class GameSignAddMember_Rules { // 清除场次
  constructor() {
    // 单元选择：必选
    this.registerTagTypeCode = [
      validator.required(translateByCode('请选择角色类型'), 'change')
    ];
    this.name = [
      validator.required(translateByCode('请填写姓名'), 'change')
    ];
    this.idCardNumber = [
      validator.required(translateByCode('请填写身份证号码'), 'change'),
      {
        validator (rule, value, callback) {
          callback(validator.checkIdNumber(value, translateByCode('身份证号码格式错误')));
        },
        trigger: 'blur'
      }
    ];
    this.phoneNumber = [
      validator.required(translateByCode('请填写手机号码'), 'change'),
      {
        validator (rule, value, callback) {
          callback(validator.checkPhone(value, translateByCode('手机号码格式错误')));
        },
        trigger: 'blur'
      }
    ];
  }
}
export class ChooseOfficial_Rules {
  constructor() {
    this.registerTagTypeCode = [
      validator.required(translateByCode('请选择角色类型'), 'change')
    ];
    this.name = [
      validator.required(translateByCode('请填写姓名'), 'blur')
    ];
    this.idCardTypeCode = [
      { required: true, message: '请选择证件类型', trigger: 'change' }
    ];
    this.idCardNumber = [
      validator.required(translateByCode('请填写身份证号码'), 'blur'),
      {
        validator (rule, value, callback) {
          callback(validator.checkIdNumber(value, translateByCode('身份证号码格式错误')));
        },
        trigger: 'blur'
      }
    ];
  }
}
// 单元设置
export class SessionInput_Rules {
  constructor() {
    this.day = [
      { required: true, message: '请选择比赛日期', trigger: 'change' }
    ];
    this.locationCodes = [
      validator.required('请选择比赛场地', 'change')
    ];
    // this.startTime1 = [
    //   validator.required('请选择上午单元开始时间', 'change')
    // ];
    // this.endTime1 = [
    //   validator.required('请选择上午单元结束时间', 'change')
    // ];
    // this.startTime2 = [
    //   validator.required('请选择中午单元开始时间', 'change')
    // ];
    // this.endTime2 = [
    //   validator.required('请选择中午单元结束时间', 'change')
    // ];
    // this.startTime3 = [
    //   validator.required('请选择下午单元开始时间', 'change')
    // ];
    // this.endTime3 = [
    //   validator.required('请选择下午单元结束时间', 'change')
    // ];
  }
}
// 添加选手报项
export class EventsManagementEntry_Rules {
  constructor() {
    this.institutionName = [
      validator.required('请输入机构名称', 'change')
    ];
    this.playerName = [
      validator.required('请输入姓名', 'change')
    ];
    this.idCardNumber = [
      validator.required(translateByCode('请填写身份证号码'), 'change'),
      {
        validator (rule, value, callback) {
          callback(validator.checkIdNumber(value, translateByCode('身份证号码格式错误')));
        },
        trigger: 'blur'
      }
    ];
  }
}
// 添加选手报项
export class PlayerDTO_PersonOfTeam_Rules {
  constructor() {
    this.teamName = [
      validator.required('请输入队伍名称', 'change')
    ];
  }
}
